#!/bin/bash

programName=JLatexEditor
programCName=jlatexeditor
svnRepo=https://endrullis.de/svn/JLatexEditor

version=$1
prefix=$programName-$version

# tag this release if we are on ahso
if [ `hostname` = "ahso" ]; then
	svn copy . $svnRepo/tags/$version -m "released version $version"
fi

mkdir -p dist/releases

# create versions.xml
cd dist/${programName}_prepare
zsh ../../scripts/create_versions_xml >versions.xml
cd ..

# replace old update dir with new one
rm -Rf $programName
mv ${programName}_prepare $programName

# pack
zip -r $prefix.zip $programName
tar -czf $prefix.tar.gz $programName

mv $prefix.* releases/

# create symbolic links (last.*)
cd releases
for ext in zip tar.gz; do
	[ -e $programName-latest.$ext ] && rm $programName-latest.$ext
	ln -s $prefix.$ext $programName-latest.$ext
done
[ -e $programCName-latest.deb ] && rm $programCName-latest.deb
ln -s ${programCName}_$version-1_all.deb $programCName-latest.deb

cd ../..

# add deb packages to Debian/Ubuntu repositories
for repo in squeeze wheezy sid lucid maverick natty oneiric; do
	reprepro -b /home/stefan/www/apt.endrullis.de includedeb $repo /home/stefan/programmierung/java/JLatexEditor/dist/releases/${programCName}_$version-1_all.deb
done
